<html>

<body onload="clock();">

<!--实现显示-->
距离本次比赛结束还有:
<form name="formnow">
    <input name="dd" type="text" style="border:0;" size=2>
    天
    <input name="hh" type="text" style="border:0;" size=2>
    小时
    <input name="mm" type="text" style="border:0;" size=2>
    分
    <input name="ss" type="text" style="border:0;" size=2>
    秒
    <div class="clear"></div>
    现在时间：
    <input name="tt" type="text" style="border:0;width: 350px" size=2>
    <div class="clear"></div>
    比赛时间：
    <input name="tt1" type="text" style="border:0;width: 350px" size=2>
</form>

</body>
</html>





<script language="JavaScript">
   // <!-- hide script from old browser
    var DifferenceHour = -1;
    var DifferenceMinute = -1;
    var DifferenceSecond = -1;
   var Sday = new Date("July 25, 2013 12:51:00")  ;
    var Eday = new Date("July 27, 2013 12:51:00")  ; //**倒计时时间点-注意格式.这里可以自己设定日期
    var daysms = 24 * 60 * 60 * 1000;
    var hoursms = 60 * 60 * 1000;
    var Secondms = 60 * 1000;
    var microsecond = 1000;
    function clock()
    {
        var time = new Date();
        var hour = time.getHours();
        var minute = time.getMinutes();
        var second = time.getSeconds();
        var timevalue = ""+((hour > 12) ? hour-12:hour);
        timevalue +=((minute < 10) ? ":0":":")+minute;
        timevalue +=((second < 10) ? ":0":":")+second;
        timevalue +=((hour >12 ) ? " PM":" AM");
// document.formnow.now.value = timevalue
        var convertHour = DifferenceHour;
        var convertMinute = DifferenceMinute;
        var convertSecond = DifferenceSecond;
        var Diffms = Eday.getTime() - time.getTime();
       var time_start = Sday.Format('yyyy-MM-dd,hh:mm:ss');

        var time_now= time.Format('yyyy-MM-dd,hh:mm:ss    星期w');
       document.formnow.tt.value=time_now;
        var time_end=Eday.Format('yyyy-MM-dd,hh:mm:ss');
        document.formnow.tt1.value=time_start +"——"+ time_end;
        if(Diffms >=0){
        DifferenceHour = Math.floor(Diffms / daysms);
        Diffms -= DifferenceHour * daysms;
        DifferenceMinute = Math.floor(Diffms / hoursms);
        Diffms -= DifferenceMinute * hoursms;
        DifferenceSecond = Math.floor(Diffms / Secondms);
        Diffms -= DifferenceSecond * Secondms;
        var dSecs = Math.floor(Diffms / microsecond);
        if(convertHour != DifferenceHour) document.formnow.dd.value=DifferenceHour;
        if(convertMinute != DifferenceMinute) document.formnow.hh.value=DifferenceMinute;
        if(convertSecond != DifferenceSecond) document.formnow.mm.value=DifferenceSecond;
        document.formnow.ss.value=dSecs;

      //  if(dSecs == 0 && convertHour==0&&convertMinute==0&&){
        if( document.formnow.hh.value==0 && document.formnow.mm.value==0 && document.formnow.dd.value==0 &&  document.formnow.ss.value == 0){
            alert('比赛结束！');
        }

// document.formnow.Tnow.value= DifferenceHour DifferenceMinute + DifferenceSecond + dSecs


        }
        else{
            document.formnow.dd.value=0;
            document.formnow.hh.value=0;
            document.formnow.mm.value=0;
            document.formnow.ss.value=0;

        }
        setTimeout("clock()",1000);
    }
    // end hiding -->



   //---------------------------------------------------
   // 日期格式化
   // 格式 YYYY/yyyy/YY/yy 表示年份
   // MM/M 月份
   // W/w 星期
   // dd/DD/d/D 日期
   // hh/HH/h/H 时间
   // mm/m 分钟
   // ss/SS/s/S 秒
   //---------------------------------------------------
   Date.prototype.Format = function(formatStr)
   {
       var str = formatStr;
       var Week = ['日','一','二','三','四','五','六'];

       str=str.replace(/yyyy|YYYY/,this.getFullYear());
       str=str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100));

       str=str.replace(/MM/,this.getMonth()>9?this.getMonth().toString():'0' +( this.getMonth()+1));
       str=str.replace(/M/g,this.getMonth());

       str=str.replace(/w|W/g,Week[this.getDay()]);

       str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate());
       str=str.replace(/d|D/g,this.getDate());

       str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours());
       str=str.replace(/h|H/g,this.getHours());
       str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():'0' + this.getMinutes());
       str=str.replace(/m/g,this.getMinutes());

       str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds());
       str=str.replace(/s|S/g,this.getSeconds());

       return str;
   }

</script>
